//
//  FZEmotionModel.swift
//  MyWeiBo
//
//  Created by fangzhengwei on 2017/4/7.
//  Copyright © 2017年 fangzhengwei. All rights reserved.
//

import UIKit

class FZEmotionModel: NSObject,NSCoding {

    //表情对应的文字
    var chs : String?
    //表情图片名
    var png : String?
    //type 暂时设置
    var type : String?
    //code码,
    var code : String?
    //图片全路径
    var allPath : String?
    
    var folderName: String?
    //  因为YYModel在给属性赋值的时候,需要使用默认的构造函数进行创建对象,对象创建完成以后才能使用kvc给属性赋值
    override init() {
        super.init()
    }
    
    //  MARK: ---归档和解档
    func encode(with aCoder: NSCoder) {
        aCoder.encode(chs, forKey: "chs")
        aCoder.encode(png, forKey: "png")
        aCoder.encode(type, forKey: "type")
        aCoder.encode(code, forKey: "code")
        aCoder.encode(allPath, forKey: "path")
        aCoder.encode(folderName, forKey: "folderName")
    }
    
    required init?(coder aDecoder: NSCoder) {
        chs = aDecoder.decodeObject(forKey: "chs") as? String
        png = aDecoder.decodeObject(forKey: "png") as? String
        type = aDecoder.decodeObject(forKey: "type") as? String
        code = aDecoder.decodeObject(forKey: "code") as? String
        allPath = aDecoder.decodeObject(forKey: "path") as? String
        folderName = aDecoder.decodeObject(forKey: "folderName") as? String
        if type == "0" {
            //  图片表情, 需要获取最新的bundle路径加载图片
            allPath = FZEmotionViewModel.sharedEmotion.Allbundle.path(forResource: folderName, ofType: nil)! + "/" + png!

        }
    }

}
